/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.tor.tribes.types;

import java.io.Serializable;
import java.util.Comparator;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Torridity
 */
@Entity
@Table(name = "GroupMemberships")
public class ZebraGroupMembership implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @OneToOne
    private ZebraUser reportUser;
    @OneToOne
    private ZebraGroup userGroup;
    @Enumerated(EnumType.STRING)
    private ZebraRole userRole;
    private boolean accepted = false;
    @Transient
    public static Comparator<ZebraGroupMembership> MEMBERSHIP_GROUP_COMPARATOR = new Comparator<ZebraGroupMembership>() {
        public int compare(ZebraGroupMembership o1, ZebraGroupMembership o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getUserGroup().getName(), o2.getUserGroup().getName());
        }
    };
    @Transient
    public static Comparator<ZebraGroupMembership> MEMBERSHIP_ROLE_COMPARATOR = new Comparator<ZebraGroupMembership>() {
        public int compare(ZebraGroupMembership o1, ZebraGroupMembership o2) {
            return o1.getRole().compareTo(o2.getRole());
        }
    };

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public ZebraUser getReportUser() {
        return reportUser;
    }

    public void setReportUser(ZebraUser user) {
        this.reportUser = user;
    }

    public ZebraGroup getUserGroup() {
        return userGroup;
    }

    public void setUserGroup(ZebraGroup group) {
        this.userGroup = group;
    }

    public void setRole(ZebraRole role) {
        this.userRole = role;
    }

    public ZebraRole getRole() {
        return userRole;
    }

    public void setAccepted(boolean accepted) {
        this.accepted = accepted;
    }

    public boolean isAccepted() {
        return accepted;
    }

    @Override
    public String toString() {
        return userGroup.toString() + " (" + userRole + ")";
    }
}
